package com.zwr.data.binarysearch;


public class BinarySearch1 {

    public static void main(String[] args) {

    }

    public static int binarySearch(int[] arr, int target) {
        int i = 0;
        int j = arr.length - 1;

        while (i <= j) {
            int m = (i + j) >>> 1;
            if (target < arr[m]) {
                j = m - 1;
            } else if (arr[m] < target) {
                i = m + 1;
            } else {
                return m;
            }
        }
        return -1;
    }
}
